<!doctype html>
<!--
 * Copyright 2016 The Chromium Authors. All rights reserved.  Use of this
 * source code is governed by a BSD-style license that can be found in the
 * LICENSE file.
-->
<html>
  <head>
    <script type="text/javascript">
      // A guest that stores and deletes cookies.
      // Note that the embedder has to initiate a postMessage first so that
      // the guest has a reference to the embedder's window.

      // The window reference of the embedder to send post message reply.
      var embedderWindowChannel = null;

      // A value that uniquely identifies the guest sending the messages to the
      // embedder.
      var channelId = 0;
      var notifyEmbedder = function(msg_array) {
        var msg = msg_array.concat([channelId]);
        embedderWindowChannel.postMessage(JSON.stringify(msg), '*');
      };

      var onPostMessageReceived = function(e) {
        embedderWindowChannel = e.source;
        var data = JSON.parse(e.data);
        if (data[0] == 'create-channel') {
          window.console.log('guest: create-channel');
          channelId = data[1];
          notifyEmbedder(['channel-created']);
          return;
        }
      };
      window.addEventListener('message', onPostMessageReceived, false);
    </script>
  </head>
  <body>
    <div>Simple guest page.</div>
  </body>
</html>
